package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.AuthorControllerApi;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;

/**
 * @Author 96558
 * @Date 2021/1/11 23:43
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {
    /**
     * 根据用户id查询作者信息
     *
     * @param userId
     * @return
     */
    @Autowired
    private AuthorService authorService;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id")  Integer id) {
        return authorService.getOne(Wrappers.
                <ApAuthor>lambdaQuery().eq(ApAuthor::getWmUserId,id));
    }

    /**
     * 保存作者
     *
     * @param apAuthor
     * @return
     */
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        authorService.save(apAuthor);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}



















